package Comunicator;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import multiplayer.PhaseControllerCliente1;

public class InputComunicatorCliente1 extends Thread implements InputComunicator{
    private PhaseControllerCliente1 controllerCliente1;
    private String ip;

    InputComunicatorCliente1(String ip, PhaseControllerCliente1 controllerCliente1) {
        this.ip = ip;
        this.controllerCliente1 = controllerCliente1;
    }

    @Override
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(5002);
            while (true){
                Socket socket = serverSocket.accept();
                InputStream inputStream = socket.getInputStream();
                ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
                controllerCliente1.setXBar2((Integer)objectInputStream.readObject());
                objectInputStream.close();
            }
        } catch (Exception ex) {
            Logger.getLogger(InputComunicatorCliente1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
